<template>
  <div class="cms_comment">
    <!-- 按钮 -->
    <div class="btns">
      <el-button size="small" type="primary" @click="toAdd">添加</el-button>
    </div>
    <!-- 表格 -->
    
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="content" label="评论内容" width="180"> </el-table-column>
      <el-table-column prop="comment_date" label="评论日期"> </el-table-column>
      <el-table-column prop="status" label="评论状态"> </el-table-column>
      <el-table-column prop="article_id" label="文章ID"> </el-table-column>
      <el-table-column prop="user_id" label="用户ID"> </el-table-column>
      <el-table-column prop="parent_id" label="父类ID"> </el-table-column>
      <el-table-column  label="操作" width="150" align="center"> 
          <template v-slot="scope">
              <el-button size="small" type="reference" @click="del(scope.row)">删除</el-button>
              <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
           </template>
      </el-table-column>
    </el-table>
    <!-- 模态框 -->
    <el-dialog
      class="customer_modal"
      title="添加配置"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handclose"
      >
    
     
     <el-form :model="form" label-width="100px">
         <el-form-item label="评论内容" >
          <el-input v-model="form.content"></el-input>
        </el-form-item>
        <el-form-item label="评论日期" >
          <el-input v-model="form.comment_date"></el-input>
        </el-form-item>
        <el-form-item label="状态" >
          <el-input v-model="form.status"></el-input>
        </el-form-item>
        <el-form-item label="文章ID" >
          <el-input v-model="form.article_id"></el-input>
        </el-form-item>
        <el-form-item label="用户ID" >
          <el-input v-model="form.user_id"></el-input>
        </el-form-item>
        <el-form-item label="父类ID" >
          <el-input v-model="form.parent_id"></el-input>
        </el-form-item>
     </el-form>

    <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="save" size="small">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {get,post} from '@/utils/request'
export default {
  data (){
    return {
        form:{},
      list:[],
      dialogVisible:false
    }
  },
  created(){
      this.loadData();
  },
   methods:{
    
    save(){
      let url = "/cms_comment/saveOrUpdate"
      get(url,this.form).then( (response)=>{
      
        this.dialogVisible = false;
        
        this.$message({type:"success",message:response.message})
        
        this.loadData();
        this.form={}
      } )
    },
  
    del(row){
        this.form=row
      let url = "/cms_comment/deleteById"
      post(url,{id:row.id}).then( (response)=>{
       
        this.$message({type:"success",message:response.message})
         
        this.loadData();
      } )
    },
    
    edit(row){
      this.form = row;
      this.dialogVisible = true;
    },
    
    loadData(){
      let url = "/cms_comment/findAll";
      get(url).then( (response)=>{
        
        this.list = response.data;
      } );
    },
    toAdd(){
      this.dialogVisible = true;
    }
  }
}

</script>


